package com.fenghongzhang.one;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private  MySqlHelp mySqlHelp;
    private SQLiteDatabase readableDatabase;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mySqlHelp = new MySqlHelp(this, "tabletest.db", null, 1);
        readableDatabase = mySqlHelp.getReadableDatabase();


        //3.进入主界面后，启动异步线程，先将table2中的数据清空。然后将下列地址存放到数据库中table2中。
        new Thread(new Runnable() {
            @Override
            public void run() {
//                readableDatabase.execSQL("delete from table2");
                readableDatabase.delete("table2",null,null);


                List<String> list = new ArrayList<>();

                list.add("http://img5.imgtn.bdimg.com/it/u=1831321739,3083785234&fm=26&gp=0.jpg");
                list.add("http://img5.imgtn.bdimg.com/it/u=1831321739,3083785234&fm=26&gp=0.jpg");
                list.add("http://img5.imgtn.bdimg.com/it/u=1831321739,3083785234&fm=26&gp=0.jpg");


                for (int i = 0; i < list.size() ; i++) {
                    ContentValues contentValues = new ContentValues();
                    contentValues.put("path",list.get(i));
                    readableDatabase.insert("table2",null,contentValues);
                }

//
//                Cursor table2 = readableDatabase.query("table2", null, null, , null, null, null);
//                if(table2 != null){
//                   while(table2.moveToNext()){
//                       String path = table2.getString(table2.getColumnIndex("path"));
//                       Log.i(TAG, "run: "+path);
//                   }
//                }

                //发送一个广播
                Intent intent = new Intent();
                intent.setAction("com.feng");
                sendBroadcast(intent);

            }
        }).start();

    }
}
